package com.suarte.core;

import com.suarte.utils.Persistent;
import java.util.Date;
import org.appfuse.model.BaseObject;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import org.appfuse.model.User;

/**
 * @date   Dec 30, 2010
 * @author Ggutierrez
 */
@Entity
@Table(name = "sa_quotation_detail")
public class QuotationDetail extends BaseObject implements Persistent {

    private Long id;
    private Quotation quotation;
    private Product product;
    private String itemDescription;
    private Integer quantity;
    private Float price;
    private Float subTotal;
    private Float tax;
    private Float total;
    private Float localPrice;
    private Float localTotal;
    private Float foreignPrice;
    private Float foreignTotal;
    private User createdBy;
    private Date createdOn = new Date();
    private User modifiedBy;
    private Date modifiedOn = new Date();
    private Long oldId;
    private Resolution resolution;
    private WorkType workType;
    private Float measure;

    public QuotationDetail() {
    }

    public QuotationDetail(Product product, Integer quantity, Float price, Float tax, Float total) {
        this.product = product;
        this.quantity = quantity;
        this.price = price;
        this.tax = tax;
        this.total = total;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "QUOTATION_DETAIL_SEQ")
    @SequenceGenerator(name = "QUOTATION_DETAIL_SEQ", sequenceName = "QUOTATION_DETAIL_SEQ", allocationSize = 1)
    public Long getId() {
        return id;
    }

    @ManyToOne
    @JoinColumn(name = "quotation_id")
    public Quotation getQuotation() {
        return quotation;
    }

    @ManyToOne
    @JoinColumn(name = "product_id")
    public Product getProduct() {
        return product;
    }

    @Column(name = "item_description", length = 300)
    public String getItemDescription() {
        return itemDescription;
    }

    @Column(name = "quantity")
    public Integer getQuantity() {
        return quantity;
    }

    @Column(name = "price")
    public Float getPrice() {
        return price;
    }

    @Column(name = "tax")
    public Float getTax() {
        return tax;
    }

    @Column(name = "subtotal")
    public Float getSubTotal() {
        return subTotal;
    }

    @Column(name = "total")
    public Float getTotal() {
        return total;
    }

    @Column(name = "local_price")
    public Float getLocalPrice() {
        return localPrice;
    }

    @Column(name = "local_total")
    public Float getLocalTotal() {
        return localTotal;
    }

    @Column(name = "foreign_price")
    public Float getForeignPrice() {
        return foreignPrice;
    }

    @Column(name = "foreign_total")
    public Float getForeignTotal() {
        return foreignTotal;
    }

    @ManyToOne
    @JoinColumn(name = "created_by")
    public User getCreatedBy() {
        return createdBy;
    }

    @Column(name = "created_on")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getCreatedOn() {
        return createdOn;
    }

    @ManyToOne
    @JoinColumn(name = "modified_by")
    public User getModifiedBy() {
        return modifiedBy;
    }

    @Column(name = "modified_on")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getModifiedOn() {
        return modifiedOn;
    }

    @Column(name = "old_id")
    public Long getOldId() {
        return oldId;
    }

    @ManyToOne
    @JoinColumn(name = "resolution_id")
    public Resolution getResolution() {
        return resolution;
    }

    @ManyToOne
    @JoinColumn(name = "work_type_id")
    public WorkType getWorkType() {
        return workType;
    }

    public Float getMeasure() {
        return measure;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setQuotation(Quotation quotation) {
        this.quotation = quotation;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public void setItemDescription(String itemDescription) {
        this.itemDescription = itemDescription;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public void setSubTotal(Float subTotal) {
        this.subTotal = subTotal;
    }

    public void setTax(Float tax) {
        this.tax = tax;
    }

    public void setTotal(Float total) {
        this.total = total;
    }

    public void setLocalPrice(Float localPrice) {
        this.localPrice = localPrice;
    }

    public void setLocalTotal(Float localTotal) {
        this.localTotal = localTotal;
    }

    public void setForeignPrice(Float foreignPrice) {
        this.foreignPrice = foreignPrice;
    }

    public void setForeignTotal(Float foreignTotal) {
        this.foreignTotal = foreignTotal;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public void setModifiedBy(User modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public void setModifiedOn(Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    public void setOldId(Long oldId) {
        this.oldId = oldId;
    }

    public void setResolution(Resolution resolution) {
        this.resolution = resolution;
    }

    public void setWorkType(WorkType workType) {
        this.workType = workType;
    }

    public void setMeasure(Float measure) {
        this.measure = measure;
    }
    
    @Override
    public String toString() {
        return product != null ? product.getDescription() : "NO PRODUCT";
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }
        if (!(other instanceof QuotationDetail)) {
            return false;
        }
        QuotationDetail _i = (QuotationDetail) other;
        return id.equals(_i.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
